<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ include file="/page/taglibs.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<%@ include file="/adapter/adapter-bootstrap.jsp" %>
<script type="text/javascript">
function deletePageParamTag(){	
	
	if(recordKey2!=""){
		if(p_del()){
		    $.ajax({
		        url:"${ctx}/sPageParamTag/deleteSPageParamTag?recordKey="+recordKey2,
		        type: "POST",      
		        dataType:"json",
		        async: false,
		        success: function(data) {
		        	if(data.flag>0){
			            alert("删除成功！");	
			            window.location.reload();
		        	}
		/* 	          $.each(data, function(index, element) {
		             window.location.reload();
		          }); */
		        },
		        error: function() {
		          alert("error");
		        }
		      });
		}

	}else{
		alert("请选择要删除的信息！");
	}

}

function createPageParamTag(code){
	window.location.href="${ctx}/sPageParamTag/jumpCreatePage?pageId=${pageId}&paramCode="+code;
	//window.showModalDialog("${ctx}/sPageParamTag/jumpCreatePage?pageId=${pageId}","dialogwidth:1200px;   dialogheight:600px;   center:yes;   Help:No;   Resizable:No;   Status:Yes;   Scroll:Yes;   Status:no;   resizable:Yes ");

}

function editPageParamTag(){
	if(recordKey2!=""){
		window.location.href="${ctx}/sPageParamTag/jumpCreatePage?recordKey="+recordKey2+"&pageId=${pageId}";
	}else{
		alert("请选择要编辑的信息！");
	}
	
}

function viewPageParamTag(){
	if(recordKey2!=""){
		window.location.href="${ctx}/sPageParamTag/jumpViewPage?recordKey="+recordKey2+"&pageId=${pageId}";
	}else{
		alert("请选择要查看的信息！");
	}
}

function p_del() { 
	var msg = "您真的确定要删除吗？\n\n请确认！"; 
	if (confirm(msg)==true){ 
	return true; 
	}else{ 
	return false; 
	} 
} 
function createTrade(){
	window.location.href="${ctx}/sPageParamTrade/jumpCreatePage?pageId=${pageId}";
}

function deleteTrade(){
	if(p_del()){
    $.ajax({
        url:"${ctx}/sPageParamTrade/deleteSpageParamTrade?tradeid="+tradeid,
        type: "POST",      
        dataType:"json",
        async: false,
        success: function(data) {
        	if(data.flag>0){
	            alert("删除成功！");	
	            window.location.reload();
        	}
/* 	          $.each(data, function(index, element) {
             window.location.reload();
          }); */
        },
        error: function() {
          alert("error");
        }
      });
	}else{
		alert("请选择要删除的数据！");
	}
}

function updateTrade(){
	if(tradeid!=""){
		window.location.href="${ctx}/sPageParamTrade/jumpEditPage?tradeid="+tradeid;
	}else{
		alert("请选择要编辑的信息！");
	}

}

</script>
</head>
<body>
<%-- <macms:table dataListName="sppmList">
	<macms:html id="ch" label="选择" innerHtml="<input type='radio' name='check' value='15' >"></macms:html>
	<macms:text id="template_param_type" label="参数类型" dictname="S_TEMPLATE_PARAM_TYPE"></macms:text>
	<macms:text id="template_param_code" label="参数代码"></macms:text>
	<macms:text id="template_param_name" label="参数名称"></macms:text>
	<macms:text id="is_must_need" label="是否必需"></macms:text>
	<macms:text id="param_value" label="参数值"></macms:text>
	<macms:text id="param_remarks" label="参数说明"></macms:text>
</macms:table> --%>




			<table id="table1" class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center" class="active">
					    <td>选择</td>
					    <td style="display: none">唯一键</td>
					    <td style="display: none">页面标识</td>
					    <td style="display: none">模板标识</td>
						<td>参数类型</td>
						<td>参数代码</td>
						<td>参数名称</td>
						<td>是否必需</td>
						<td>参数值</td>
						<td>参数说明</td>
					</tr>
				</thead>				
				<tbody>
					<c:forEach items="${pageParamList}" var="pageParam" varStatus="s" >
					  <c:if test="${pageParam.templateParamType=='01'}">
 						<tr align="center">
 						    <td><input type="radio" name="check" id="check" value="15"></input></td>
							<td style="display: none">${pageParam.recordKey}</td>
					        <td style="display: none">${pageParam.pageId}</td>
					        <td style="display: none">${pageParam.templateId}</td>
							
							<td>${pageParam.templateParamType}</td>
							<td>${pageParam.templateParamCode}</td>
							<td>${pageParam.templateParamName}</td>
							<td>${pageParam.isMustNeed}</td>
							<td>
							<input type="text"  id="param${pageParam.recordKey}" ondblclick="paramClick(this,'${pageParam.recordKey}')" value="${pageParam.paramValue}"  readOnly   onblur="getParamValue(this.value)"/>
							<input type="button" style="display:none" id="${pageParam.recordKey}" value="修改" onclick="saveParam('${pageParam.recordKey}')">
							<%-- <c:if test="${pageParam.templateParamType!='01'}">
								...
							</c:if> --%>
							</td>
							<td>${pageParam.paramRemarks}</td>							
						</tr> 
					  </c:if>		
						</c:forEach>																					
				</tbody>
			</table>
	<div class="panel panel-default" id="tagArea">
   		<div class="panel-body">
   			<c:forEach items="${tagmap }" var="map">
				<form class="form-horizontal" role="form" method="post" action="${ctx}/pagemgr/templateParam.do?page_id=${pageId}">
   		<div>${map.key.templateParamName}</div>
   			<div>
				<input type="button" class="btn btn-default" value="添加标签参数" onclick="createPageParamTag('${map.key.templateParamCode}');"/>
				<input type="button" class="btn btn-default" value="删除标签参数" onclick="deletePageParamTag();"/>
				<input type="button" class="btn btn-default" value="编辑标签参数" onclick="editPageParamTag();"/>
				<input type="button" class="btn btn-default" value="查看标签参数" onclick="viewPageParamTag();"/>
			</div>	
			<table id="table2" class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center" class="active">
					    <td>选择</td>
					    <td>标签唯一标识</td>
					    <td>归属页面标识</td>
					    <td>归属参数代码</td>
						<td><c:choose><c:when test="${map.key.templateParamCode=='beanColumns'}">属性类型</c:when><c:otherwise>标签名称</c:otherwise></c:choose></td>
						<td>标签类型</td>
						<td><c:choose><c:when test="${map.key.templateParamCode=='beanColumns'}">属性名称</c:when><c:otherwise>标签取值</c:otherwise></c:choose></td>
					</tr>
				</thead>				
				<tbody>
					<c:forEach items="${map.value}" var="pageParamTag" varStatus="s" >
 						<tr align="center">
 						    <td><input type="radio" name="check" id="check" value="15"></input></td>
							<td>${pageParamTag.recordKey}</td>
					        <td>${pageParamTag.pageId}</td>
					        <td>${pageParamTag.templateParamCode}</td>
							<td>${pageParamTag.tagName}</td>
							<td>${pageParamTag.tagType}</td>
							<td>${pageParamTag.tagValueSrc}</td>						
						</tr> 		
						</c:forEach>
				</tbody>
			</table>
			<%-- <%@ include file="/page/page.jsp" %> --%>
			</form>	
			</c:forEach>
			<c:if test="${fn:length(tradelist)>0}">
				<form class="form-horizontal" role="form" method="post" action="${ctx}/sPageParamTrade/jumpListPage.do?pageId=${pageId}">
   		<div>${templateTradName}</div>
   			<div>
				<input type="button" class="btn btn-default" value="创建交易参数" onclick="createTrade()" />
				<input type="button" class="btn btn-default" value="删除交易参数" onclick="deleteTrade()"/>
				<input type="button" class="btn btn-default" value="编辑交易参数" onclick="updateTrade()"/>
			</div>	
			<table id="table3" class="table table-bordered" style="" width="100%" cellspacing="1" cellpadding="0" border="0">
				<thead>
					<tr align="center" class="active">
					    <td>选择</td>
					    <td>交易标识</td>
					    <td>页面标识</td>
					    <td>交易码</td>
						<td>交易名称</td>
						<td>交易描述</td>
						<td>输入格式化</td>
						<td>输出格式化</td>
					</tr>
				</thead>				
				<tbody>
					<c:forEach items="${tradelist}" var="pagetrade" varStatus="s" >
 						<tr align="center">
 						    <td><input type="radio" name="check" id="check" value="15"></input></td>
							<td>${pagetrade.tradeId}</td>
					        <td>${pagetrade.pageId}</td>
					        <td>${pagetrade.tradeCode}</td>
							<td>${pagetrade.tradeName}</td>
							<td>${pagetrade.tradeDesc}</td>
							<td>${pagetrade.tradeInFormat}</td>
							<td>${pagetrade.tradeOutFormat}</td>						
						</tr> 		
						</c:forEach>
				</tbody>
			</table>
			<%-- <%@ include file="/page/page.jsp" %> --%>
			</form>
			</c:if>
   		</div>
	</div>
	<script language="javascript">
	    var preRow = null;
	    var paramvalue="";
		$('#table1 tr').bind('click', function() {
	
			//var recordKey;
			//var pageId;
			//var tagName;
			var rowIndex = $(this).prevAll().length+1;
			if(rowIndex <1) return;
			
			if(preRow != null){
				preRow.removeClass("active");
			}
			$(this).addClass("active");
			preRow = $(this);
			//document.getElementById('tagArea').style.display = "none";
			if($(this).find("td").eq(4).text()=='02'){
				 //recordKey= $(this).find("td").eq(1).text();
				 //pageId=$(this).find("td").eq(2).text();
				 //tagName = $(this).find("td").eq(6).text();
				 //document.getElementById('tagArea').style.display = "block";
				 //window.location.href="${pageContext.request.contextPath }/sPageParamTag/querySPageParamTagList?recordKey="+recordKey+"&pageId="+pageId+"&tagName="+tagName;
				//window.showModalDialog("${pageContext.request.contextPath }/sPageParamTag/querySPageParamTagList?recordKey="+recordKey+"&pageId="+pageId,window,"dialogwidth:1200px;   dialogheight:600px;   center:yes;   Help:No;   Resizable:No;   Status:Yes;   Scroll:Yes;   Status:no;   resizable:no ");
				//JLUtil.woInFull("${pageContext.request.contextPath }/sPageParamTag/querySPageParamTagList?recordKey="+recordKey+"&pageId="+pageId) ;

			}
			
			if($(this).find("td").eq(4).text()=='03'){
				// recordKey= $(this).find("td").eq(1).text();
				 //pageId=$(this).find("td").eq(2).text();
				 //document.getElementById('tagArea').style.display = "none";
				//window.showModalDialog("${pageContext.request.contextPath }/sPageParamTrade/jumpListPage?pageId="+pageId,window,"dialogwidth:1200px;   dialogheight:600px;   center:yes;   Help:No;   Resizable:No;   Status:Yes;   Scroll:Yes;   Status:no;   resizable:no ");
				//JLUtil.woInFull("${pageContext.request.contextPath }/sPageParamTrade/jumpListPage?pageId="+pageId);

			}
			
/* 			function addrow()
			{
			        var html=window.showModalDialog("${pageContext.request.contextPath }/plupmodule/modulepagelist",window,"dialogwidth:1200px;   dialogheight:650px;   center:yes;   Help:No;   Resizable:No;   Status:Yes;   Scroll:Yes;   Status:no;   resizable:no ");
			        $("table").append(html); 
				  
			} */
			// 行单击后事件(传入行号，应用ID,应用名称信息)
			//rowClickAfter(rowIndex,
			//		$(this).find("td").eq(1).text(),
			//		$(this).find("td").eq(2).text());
		});
		

		function getParamValue(pvalue){
			paramvalue=pvalue;
			//$('#edit').hide();
		}
		
 		function paramClick(obj,pv) {
			obj.readOnly = false;
			//document.getElementById('edit').style.display = "block";
			$('#'+pv).show();
			//$('#paramValue').attr("readonly",true);

		} 
		
		  function saveParam(recordKey){
			$('#param'+recordKey).attr("readonly",true);
		    $.ajax({
		        url: "${ctx}/pageTemplateParam/savePageTemplateParam",
		        type: "POST",      
		        dataType:"json",
		        data:{'recordKey':recordKey, 'paramvalue':paramvalue},
		        async: false,
		        success: function(data) {
					document.getElementById(recordKey).style.display = "none";
		        	if(data.flag>0){
			            alert("修改成功！");	
		        	}

	/* 	          $.each(data, function(index, element) {
		             window.location.reload();
		          }); */
		        },
		        error: function() {
				  document.getElementById(recordKey).style.display = "none";
		          alert("error");
		        }
		      });
	  }
		  function saveParam1(recordKey){
			  alert(paramvalue);
			  $('#param'+recordKey).attr("readonly",true);
			  document.getElementById(recordKey).style.display = "none";
		  }
		    var recordKey2="";
		    var paramCode="";
		    var preRow2 = null;
			$('#table2 tr').bind('click', function() {
		
				var rowIndex = $(this).prevAll().length+1;
				if(rowIndex <1) return;
				if(preRow2 != null){
					preRow2.removeClass("active");
				}
				$(this).addClass("active");
				preRow2 = $(this);
				
				recordKey2=$(this).find("td").eq(1).text();
				paramCode=$(this).find("td").eq(3).text();
				// 行单击后事件(传入行号，应用ID,应用名称信息)

			});
			var preRow3 = null;
		    var tradeid="";
			$('#table3 tr').bind('click', function() {

				var rowIndex = $(this).prevAll().length+1;
				if(rowIndex <1) return;
				
				if(preRow3 != null){
					preRow3.removeClass("active");
				}
				$(this).addClass("active");
				preRow3 = $(this);
				
				tradeid=$(this).find("td").eq(1).text();
				// 行单击后事件(传入行号，应用ID,应用名称信息)
				/* rowClickAfter(rowIndex,
						$(this).find("td").eq(1).text(),
						$(this).find("td").eq(2).text()); */
				
			});
	</script>
</body>
</html>
